import { defineStore } from "pinia";
import { reactive } from "vue";
import { getSystemListAPI, chatMessageListAPI } from '@/api/message'

export const messageStore = defineStore('mssage', () => {
    // state
    const state = reactive({
        systemMessageList: [],
        systemNewMessage: [],
        chatMessageList: []
    })

    // 获取消息列表
    const getSystemMessageList = async() => {
        const res = await getSystemListAPI({
            type: 0,
            is_informtype: 2
        })
        if (res) {
            state.systemMessageList = res.data
            if (state.systemMessageList[0]) {
                state.systemNewMessage = [state.systemMessageList[0]]
            }
        }
    }
    // 获取对话列表
    const getChatMessageList = async() => {
        const res = await chatMessageListAPI()        
        if (res) {
            state.chatMessageList = res.data
        }
    }

    return {
        state,
        getSystemMessageList,
        getChatMessageList
    }
})